#include "thread_array.h"
#include <stdio.h>
#include <pthread.h>

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void call_back(void * argv)
{
    int *str = argv;
    //获取锁
    pthread_mutex_lock(&mutex);
    *str += 1;
    //释放锁
    pthread_mutex_unlock(&mutex);
}

int main(int argc, char const *argv[])
{
    int num = 0;
    //创建一个任务
    Task task;
    task.task_func = call_back;
    task.argv = &num;

    //初始化县城池
    int result =  Thread_Array_Init(10);
    //判断是否初始化成功
    if(result != 0)
    {
        //失败
        printf("线程池初始化失败\n");
        return -1;
    }

    //注册20000个任务
    for(int i = 0;i < 20000 ;i++)
    {
        result = Thread_RegisterTask(&task);
        if(result != 0)
        {
            printf("注册任务失败\n");
            return -1;
        }
    }

    //等待num 加到20000
    while(num == 20000);

    //删除线程池
    Thread_close();

    printf("num = %d\n",num);
    return 0;
}
